package com.hdoit.kylin.web.studentManager.providers;

import java.util.ArrayList;
import java.util.List;
import com.hdoit.kylin.logical.user.model.Teacher;
import com.hdoit.kylin.logical.user.service.IStudentService;
import com.hdoit.kylin.logical.user.service.ITeacherService;
import com.hdoit.kylin.web.common.CommonWebUtils;
import com.tennetcn.common.aop.CommonApplicationContextUtil;
import com.tennetcn.common.message.ListItem;
import com.tennetcn.common.message.LoginModel;
import com.tennetcn.component.attribute.provider.ISingleOptionListProvider;
import com.tennetcn.component.web.SessionWebFactory;
import com.tennetcn.web.cbase.providers.base.DataListProviderBase;

/**
 * @author chenghuan
 * @email 79763939@qq.com
 * @createtime 2017年5月17日 上午9:17:39
 * @comment
 */
public class TeacherOwnProvider extends  DataListProviderBase implements ISingleOptionListProvider<ListItem> {
	
	@Override
	public List<ListItem> getDataList(Object viewData) {
		List<Teacher> teachers = getOwnProjectList();
		if (teachers == null || teachers.size() <= 0) {
			return null;
		}
		dataList = new ArrayList<ListItem>();
		ListItem listItem = null;
		for (Teacher teacher : teachers) {
			listItem = new ListItem();
			listItem.setText(teacher.getTeacherName());
			listItem.setValue(teacher.getEmployeeId());
			dataList.add(listItem);
		}
		return dataList;
	}


	private List<Teacher> getOwnProjectList() {
		SessionWebFactory sessionWebFactory = CommonApplicationContextUtil.getCurrentContext()
				.getBean(SessionWebFactory.class);
		LoginModel loginModel = sessionWebFactory.getCurrentLogin();
		String groupId = null;

		ITeacherService teacherService = CommonApplicationContextUtil.getCurrentContext()
				.getBean(ITeacherService.class);

		if (CommonWebUtils.isTeacher(loginModel)) {
			groupId = teacherService.queryGroupIdByLoginId(loginModel.getLoginId());
			return teacherService.queryListByGroupId(groupId);
		} else if (CommonWebUtils.isStudent(loginModel)) {
			IStudentService studentService = CommonApplicationContextUtil.getCurrentContext()
					.getBean(IStudentService.class);
			groupId = studentService.queryGroupIdByLoginId(loginModel.getLoginId());
			return teacherService.queryListByGroupId(groupId);
		}
		return teacherService.queryList();
	}
}
